package com.maotai.util;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
import org.apache.http.conn.util.PublicSuffixMatcher;
import org.apache.http.conn.util.PublicSuffixMatcherLoader;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import com.maotai.bean.MaotaiWebCookie;

public class HttpClientUtil {
	private RequestConfig requestConfig = RequestConfig.custom()
			.setSocketTimeout(3000000).setConnectTimeout(3000000)
			.setConnectionRequestTimeout(3000000).build();

	private static HttpClientUtil instance = null;

	private HttpClientUtil() {
	}

	public static HttpClientUtil getInstance() {
		if (instance == null) {
			instance = new HttpClientUtil();
		}
		return instance;
	}

	/**
	 * 
	 * @param httpUrl
	 */
	public String sendGetAlicdn(String httpUrl) {
		HttpGet httpGet = new HttpGet(httpUrl);
		httpGet = setHttpGetAlicdnHeader(httpGet);
		return sendHttpGetAlicdn(httpGet);
	}
	public String sendHttpGetLogin(String httpUrl) {
		HttpGet httpGet = new HttpGet(httpUrl);
		httpGet = setHttpGetLoginHeader(httpGet);
		return sendHttpGetLogin(httpGet);
	}
	public MaotaiWebCookie sendHttpGetKuCun(String httpUrl,MaotaiWebCookie mwc) {
		HttpGet httpGet = new HttpGet(httpUrl);
		httpGet = setHttpGetKuCunHeader(httpGet,mwc);
		return sendHttpGetKuCun(httpGet,mwc);
	}
	public MaotaiWebCookie sendHttpGetSubmmitOrder(String httpUrl,MaotaiWebCookie mwc) {
		HttpGet httpGet = new HttpGet(httpUrl);
		httpGet = setHttpGetSubmmitOrderHeader(httpGet,mwc);
		return sendHttpGetSubmmitOrder(httpGet,mwc);
	}
	public MaotaiWebCookie sendHttpGetSubmmitOrderProxy(String httpUrl,MaotaiWebCookie mwc, RequestConfig config) {
		HttpGet httpGet = new HttpGet(httpUrl);
		httpGet = setHttpGetSubmmitOrderHeader(httpGet,mwc);
		return sendHttpGetSubmmitOrderProxy(httpGet,mwc,config);
	}
	public MaotaiWebCookie sendHttpGetVerifyCodeImage(String httpUrl,MaotaiWebCookie mwc) {
		HttpGet httpGet = new HttpGet(httpUrl);
		httpGet = setHttpGetVerifyCodeImageHeader(httpGet,mwc);
		return sendHttpGetVerifyCodeImage(httpGet,mwc);
	}
	/**
	 * 
	 * @param httpUrl
	 */
	public String sendHttpsGet(String httpUrl) {
		HttpGet httpGet = new HttpGet(httpUrl);
		setHttpGetHeader(httpGet);
		return sendHttpsGet(httpGet);
	}
	/**
	 * 
	 * @param httpUrl
	 */
	
	private MaotaiWebCookie sendHttpGetVerifyCodeImage(HttpGet httpGet, MaotaiWebCookie mwc) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		try {
			httpClient = HttpClients.createDefault();
			httpGet.setConfig(requestConfig);
			response = httpClient.execute(httpGet);
			Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}else if(hea.getValue().startsWith("VerifyCode")){
							if(!hea.getValue().startsWith("VerifyCode=;"))
									mwc.setVerifyCode(hea.getValue());
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return mwc;
	}
	private MaotaiWebCookie sendHttpGetSubmmitOrder(HttpGet httpGet,MaotaiWebCookie mwc) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String return_str = null;
		try {
			httpClient = HttpClients.createDefault();
			
			httpGet.setConfig(requestConfig);
			response = httpClient.execute(httpGet);
			Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}
					}
				}
			}
			entity = response.getEntity();
			return_str = EntityUtils.toString(entity, "UTF-8");
			mwc.setContent(return_str);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return mwc;
	}
	private MaotaiWebCookie sendHttpGetSubmmitOrderProxy(HttpGet httpGet,MaotaiWebCookie mwc, RequestConfig config) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String return_str = null;
		try {
			httpClient = HttpClients.createDefault();
			
			httpGet.setConfig(config);
			response = httpClient.execute(httpGet);
			Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}
					}
				}
			}
			entity = response.getEntity();
			return_str = EntityUtils.toString(entity, "UTF-8");
			mwc.setContent(return_str);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return mwc;
	}
	private MaotaiWebCookie sendHttpGetKuCun(HttpGet httpGet,MaotaiWebCookie mwc) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String return_str = null;
		try {
			httpClient = HttpClients.createDefault();
			
			httpGet.setConfig(requestConfig);
			response = httpClient.execute(httpGet);
			Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}else if(hea.getValue().startsWith("BrowedProductList-Admin")){
							mwc.setBrowedProductList(hea.getValue());
						}
					}
				}
			}
			entity = response.getEntity();
			if(entity!=null){
				return_str = EntityUtils.toString(entity, "UTF-8");
				mwc.setContent(return_str);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return mwc;
	}
	private String sendHttpGetLogin(HttpGet httpGet) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String return_str = null;
		try {
			httpClient = HttpClients.createDefault();
			
			httpGet.setConfig(requestConfig);
			response = httpClient.execute(httpGet);
			Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						System.out.println(hea.getValue()+"----"+hea.getValue());
					}
				}
			}
			entity = response.getEntity();
			return_str = EntityUtils.toString(entity, "UTF-8");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return return_str;
	}
	private String sendHttpGetAlicdn(HttpGet httpGet) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String return_str = null;
		try {
			httpClient = HttpClients.createDefault();
			
			httpGet.setConfig(requestConfig);
			response = httpClient.execute(httpGet);
			entity = response.getEntity();
			return_str = EntityUtils.toString(entity, "UTF-8");
			System.out.println(return_str);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return return_str;
	}
	/**
	 * ����Get����Https
	 * 
	 * @param httpPost
	 * @return
	 */
	private String sendHttpsGet(HttpGet httpGet) {
		CloseableHttpClient httpClient = null;
		CloseableHttpResponse response = null;
		HttpEntity entity = null;
		String responseContent = null;
		try {
			PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader
					.load(new URL(httpGet.getURI().toString()));
			DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(
					publicSuffixMatcher);
			httpClient = HttpClients.custom()
					.setSSLHostnameVerifier(hostnameVerifier).build();
			httpGet.setConfig(requestConfig);
			response = httpClient.execute(httpGet);
			entity = response.getEntity();
			responseContent = EntityUtils.toString(entity, "UTF-8");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (response != null) {
					response.close();
				}
				if (httpClient != null) {
					httpClient.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return responseContent;
	}
	
	private HttpGet setHttpGetVerifyCodeImageHeader(HttpGet httpGet,MaotaiWebCookie mwc) {
		httpGet.addHeader("Accept",
				"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
		httpGet.addHeader("Accept-Encoding", "gzip, deflate, sdch, br");
		httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httpGet.addHeader("Connection", "keep-alive");
		httpGet.addHeader("Host", "www.emaotai.cn");
		httpGet.addHeader("Referer", "https://www.emaotai.cn/product_detail-432.htm");
		httpGet.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		httpGet.addHeader("Cookie", "acw_tc=AQAAAGQf8APS3gwAWIhitFe9DokQv8au; _uab_collina=151226359216384375091202; SERVERID=b6577c15156ac417dd3239281b2060d5|1512264232|1512263633; Hm_lvt_c3450451979c90e739797559911899fd=1512263593; Hm_lpvt_c3450451979c90e739797559911899fd=1512264190; _umdata=0712F33290AB8A6D07BFC7B196FE12F69C87119A762AE630D4E12189435F8E48C7C4B62977D3AE33CD43AD3E795C914CE0B9E3FB2DD88D64C5B57EE420BE5877;"
				+mwc.getHidistro()+";"+mwc.getServerId()+";"+mwc.getBrowedProductList()+";"+mwc.getHishopRoles());
		return httpGet;
	}
	private HttpGet setHttpGetSubmmitOrderHeader(HttpGet httpGet,MaotaiWebCookie mwc) {
		httpGet.addHeader("Accept",
				"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
		httpGet.addHeader("Accept-Encoding", "gzip, deflate, sdch, br");
		httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httpGet.addHeader("Connection", "keep-alive");
		httpGet.addHeader("Host", "www.emaotai.cn");
		httpGet.addHeader("Referer", "https://www.emaotai.cn/product_detail-432.htm");
		httpGet.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		httpGet.addHeader("Cookie", "acw_tc=AQAAAGQf8APS3gwAWIhitFe9DokQv8au; _uab_collina=151226359216384375091202; SERVERID=b6577c15156ac417dd3239281b2060d5|1512264232|1512263633; Hm_lvt_c3450451979c90e739797559911899fd=1512263593; Hm_lpvt_c3450451979c90e739797559911899fd=1512264190; _umdata=0712F33290AB8A6D07BFC7B196FE12F69C87119A762AE630D4E12189435F8E48C7C4B62977D3AE33CD43AD3E795C914CE0B9E3FB2DD88D64C5B57EE420BE5877;"
				+mwc.getHidistro()+";"+mwc.getServerId()+";"+mwc.getBrowedProductList()+";"+mwc.getVerifyCode()+";"+mwc.getHishopRoles());
		return httpGet;
	}
	private HttpGet setHttpGetKuCunHeader(HttpGet httpGet,MaotaiWebCookie mwc) {
		httpGet.addHeader("Accept",
				"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
		httpGet.addHeader("Accept-Encoding", "gzip, deflate, sdch, br");
		httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httpGet.addHeader("Connection", "keep-alive");
		httpGet.addHeader("Host", "www.emaotai.cn");
		httpGet.addHeader("Referer", "https://www.emaotai.cn/");
		httpGet.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		httpGet.addHeader("Cookie", "acw_tc=AQAAAGQf8APS3gwAWIhitFe9DokQv8au; _uab_collina=151226359216384375091202; SERVERID=b6577c15156ac417dd3239281b2060d5|1512264232|1512263633; Hm_lvt_c3450451979c90e739797559911899fd=1512263593; Hm_lpvt_c3450451979c90e739797559911899fd=1512264190; _umdata=0712F33290AB8A6D07BFC7B196FE12F69C87119A762AE630D4E12189435F8E48C7C4B62977D3AE33CD43AD3E795C914CE0B9E3FB2DD88D64C5B57EE420BE5877;"
				+mwc.getHidistro());
		return httpGet;
	}
	private HttpGet setHttpGetLoginHeader(HttpGet httpGet) {
		httpGet.addHeader("Accept",
				"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
		httpGet.addHeader("Accept-Encoding", "gzip, deflate, br");
		httpGet.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httpGet.addHeader("Connection", "keep-alive");
		httpGet.addHeader("Host", "www.emaotai.cn");
		httpGet.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36");
		httpGet.addHeader("Cookie", "acw_tc=AQAAAGQf8APS3gwAWIhitFe9DokQv8au; _uab_collina=151226359216384375091202; SERVERID=b6577c15156ac417dd3239281b2060d5|1512264232|1512263633; Hm_lvt_c3450451979c90e739797559911899fd=1512263593; Hm_lpvt_c3450451979c90e739797559911899fd=1512264190; _umdata=0712F33290AB8A6D07BFC7B196FE12F69C87119A762AE630D4E12189435F8E48C7C4B62977D3AE33CD43AD3E795C914CE0B9E3FB2DD88D64C5B57EE420BE5877");
		return httpGet;
	}
	
	private HttpGet setHttpGetAlicdnHeader(HttpGet httpGet) {
		httpGet.addHeader("Accept",
				"*/*");
		httpGet.addHeader("Accept-Encoding", "gzip, deflate, sdch, br");
		httpGet.addHeader("Accept-Language", " zh-CN,zh;q=0.8");
		httpGet.addHeader("referer", "https://www.emaotai.cn/login.aspx");
		httpGet.addHeader("Host", "cf.aliyun.com");
		httpGet.addHeader(
				"User-Agent",
				" Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		return httpGet;
	}
	private HttpGet setHttpGetHeader(HttpGet httpGet) {
		httpGet.addHeader("Accept",
				"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
		httpGet.addHeader("Accept-Encoding", "gzip,deflate");
		httpGet.addHeader("Accept-Language", "zh-CN,en-US;q=0.8");
		httpGet.addHeader("Connection", "keep-alive");
		httpGet.addHeader("Host", "www.cmaotai.com");
		httpGet.addHeader("Origin", "https://appleid.apple.com");
		httpGet.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Linux; Android 4.4.4; Che1-CL10 Build/Che1-CL10) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36[android/1.0.21/36ecb0f48aeee595d31cf0b2c7f0d724/a08229b288a99b46dceae14dbbb6bbfb]");
		return httpGet;
	}
	
	private HttpPost setHttpPostShoppingHandlerHeader(HttpPost httpPost,MaotaiWebCookie mwc) {
		httpPost.addHeader("Accept","application/json, text/javascript, */*; q=0.01");
		httpPost.addHeader("Accept-Encoding", "gzip, deflate, br");
		httpPost.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httpPost.addHeader("Connection", "keep-alive");
		httpPost.addHeader("Host", "www.emaotai.cn");
		httpPost.addHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		httpPost.addHeader("Origin","https://www.emaotai.cn");
		httpPost.addHeader("Referer","https://www.emaotai.cn/product_detail-432.htm");
		httpPost.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		httpPost.addHeader("Cookie", "acw_tc=AQAAAGQf8APS3gwAWIhitFe9DokQv8au; _uab_collina=151226359216384375091202; Hm_lvt_c3450451979c90e739797559911899fd=1512263593; Hm_lpvt_c3450451979c90e739797559911899fd=1512271437; SERVERID=9f18f14edeb065e933309166dbbcfcc0|1512271489|1512263633; _umdata=0712F33290AB8A6D07BFC7B196FE12F69C87119A762AE630D4E12189435F8E48C7C4B62977D3AE33CD43AD3E795C914CE0B9E3FB2DD88D64C5B57EE420BE5877;"
				+mwc.getHidistro()+";"+mwc.getServerId()+";"+mwc.getBrowedProductList()+";"+mwc.getVerifyCode()+";"+mwc.getHishopRoles());
		return httpPost;
	}
	
	private HttpPost setHttpPostSubmmitOrderHeader(HttpPost httpPost, MaotaiWebCookie mwc ,String referer) {
		httpPost.addHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
		httpPost.addHeader("Accept-Encoding", "gzip, deflate, br");
		httpPost.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httpPost.addHeader("Connection", "keep-alive");
		httpPost.addHeader("Host", "www.emaotai.cn");
		httpPost.addHeader("Content-Type","application/x-www-form-urlencoded");
		httpPost.addHeader("Origin","https://www.emaotai.cn");
		httpPost.addHeader("Referer",referer);
		httpPost.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		httpPost.addHeader("Cookie", "acw_tc=AQAAAGQf8APS3gwAWIhitFe9DokQv8au; _uab_collina=151226359216384375091202; SERVERID=b6577c15156ac417dd3239281b2060d5|1512264232|1512263633; Hm_lvt_c3450451979c90e739797559911899fd=1512263593; Hm_lpvt_c3450451979c90e739797559911899fd=1512264190; _umdata=0712F33290AB8A6D07BFC7B196FE12F69C87119A762AE630D4E12189435F8E48C7C4B62977D3AE33CD43AD3E795C914CE0B9E3FB2DD88D64C5B57EE420BE5877;"
				+mwc.getHidistro()+";"+mwc.getServerId()+";"+mwc.getBrowedProductList()+";"+mwc.getVerifyCode()+";"+mwc.getHishopRoles());
		return httpPost;
	}
	private HttpPost setHttpPostGetUserShippingAddressHeader(HttpPost httpPost, MaotaiWebCookie mwc ,String referer) {
		httpPost.addHeader("Accept","application/json, text/javascript, */*; q=0.01");
		httpPost.addHeader("Accept-Encoding", "gzip, deflate, br");
		httpPost.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httpPost.addHeader("Connection", "keep-alive");
		httpPost.addHeader("Host", "www.emaotai.cn");
		httpPost.addHeader("Content-Type","application/x-www-form-urlencoded");
		httpPost.addHeader("Origin","https://www.emaotai.cn");
		httpPost.addHeader("Referer",referer);
		httpPost.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		httpPost.addHeader("Cookie", "acw_tc=AQAAAGQf8APS3gwAWIhitFe9DokQv8au; _uab_collina=151226359216384375091202; SERVERID=b6577c15156ac417dd3239281b2060d5|1512264232|1512263633; Hm_lvt_c3450451979c90e739797559911899fd=1512263593; Hm_lpvt_c3450451979c90e739797559911899fd=1512264190; _umdata=0712F33290AB8A6D07BFC7B196FE12F69C87119A762AE630D4E12189435F8E48C7C4B62977D3AE33CD43AD3E795C914CE0B9E3FB2DD88D64C5B57EE420BE5877;"
				+mwc.getHidistro()+";"+mwc.getServerId()+";"+mwc.getBrowedProductList()+";"+mwc.getVerifyCode()+";"+mwc.getHishopRoles());
		return httpPost;
	}
	private HttpPost setHttpPostLoginHeader(HttpPost httpPost) {
		httpPost.addHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
		httpPost.addHeader("Accept-Encoding", "gzip, deflate, sdch, br");
		httpPost.addHeader("Accept-Language", "zh-CN,zh;q=0.8");
		httpPost.addHeader("Connection", "keep-alive");
		httpPost.addHeader("Host", "www.emaotai.cn");
		httpPost.addHeader("Content-Type","application/x-www-form-urlencoded");
		httpPost.addHeader("Origin","https://www.emaotai.cn");
		httpPost.addHeader("Referer","https://www.emaotai.cn/login.aspx");
		httpPost.addHeader(
				"User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
		httpPost.addHeader("Cookie", "acw_tc=AQAAAGQf8APS3gwAWIhitFe9DokQv8au; _uab_collina=151226359216384375091202; Hm_lvt_c3450451979c90e739797559911899fd=1512263593; Hm_lpvt_c3450451979c90e739797559911899fd=1512271437; SERVERID=9f18f14edeb065e933309166dbbcfcc0|1512271489|1512263633; _umdata=0712F33290AB8A6D07BFC7B196FE12F69C87119A762AE630D4E12189435F8E48C7C4B62977D3AE33CD43AD3E795C914CE0B9E3FB2DD88D64C5B57EE420BE5877");
		return httpPost;
	}
	 /** 
     * @param httpUrl ��ַ 
     */  
    public String sendHttpPost(String httpUrl) {  
        HttpPost httpPost = new HttpPost(httpUrl);// ����httpPost    
        return sendHttpPost(httpPost);  
    } 
    public MaotaiWebCookie sendHttpPostLogin(String httpUrl, Map<String, String> maps) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostLoginHeader(httpPost);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpLoginPost(httpPost);  
    }
    public MaotaiWebCookie sendHttpPostLoginProxy(String httpUrl, Map<String, String> maps,RequestConfig requestConfig) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostLoginHeader(httpPost);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpLoginPostProxy(httpPost,requestConfig);  
    }
    public MaotaiWebCookie sendHttpPostSendSms(String httpUrl,MaotaiWebCookie mwc , Map<String, String> maps, String referer) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostGetUserShippingAddressHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpGetUserShippingAddressPost(httpPost,mwc);  
    }
    public MaotaiWebCookie sendHttpPostSendSmsProxy(String httpUrl,MaotaiWebCookie mwc , Map<String, String> maps, String referer,RequestConfig requestConfig) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostGetUserShippingAddressHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpGetUserShippingAddressPostProxy(httpPost,mwc,requestConfig);  
    }
    public MaotaiWebCookie sendHttpPostGetUserShippingAddress(String httpUrl,MaotaiWebCookie mwc , Map<String, String> maps, String referer) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostGetUserShippingAddressHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpGetUserShippingAddressPost(httpPost,mwc);  
    }
    
    public MaotaiWebCookie sendHttpPostGetRegions(String httpUrl,MaotaiWebCookie mwc, Map<String, String> maps, String referer) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostGetUserShippingAddressHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpGetUserShippingAddressPost(httpPost,mwc);  
    }
    public MaotaiWebCookie sendHttpPostCheckIsYuYue(String httpUrl,MaotaiWebCookie mwc, Map<String, String> maps, String referer) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostGetUserShippingAddressHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpGetUserShippingAddressPost(httpPost,mwc);  
    }
    public MaotaiWebCookie sendHttpPostGetMyInvoiceForQian(String httpUrl,MaotaiWebCookie mwc, Map<String, String> maps, String referer) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostGetUserShippingAddressHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpGetUserShippingAddressPost(httpPost,mwc);  
    }
    public MaotaiWebCookie sendHttpPostGetRegionInfoAddress(String httpUrl,MaotaiWebCookie mwc, Map<String, String> maps, String referer) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostGetUserShippingAddressHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpGetUserShippingAddressPost(httpPost,mwc);  
    }
    public MaotaiWebCookie sendHttpPostSubmmitOrder(String httpUrl,MaotaiWebCookie mwc, Map<String, String> maps, String referer) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostSubmmitOrderHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpPostSubmmitOrder(httpPost,mwc);  
    }
    public MaotaiWebCookie sendHttpPostRegisterProxy(String httpUrl,MaotaiWebCookie mwc, Map<String, String> maps, String referer,RequestConfig config) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostSubmmitOrderHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpPostSubmmitOrderProxy(httpPost,mwc,config);  
    }
    public MaotaiWebCookie sendHttpPostRegister(String httpUrl,MaotaiWebCookie mwc, Map<String, String> maps, String referer) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostSubmmitOrderHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpPostSubmmitOrder(httpPost,mwc);  
    }
    public MaotaiWebCookie sendHttpPostSubmmitOrderProxy(String httpUrl,MaotaiWebCookie mwc, Map<String, String> maps, String referer,RequestConfig config) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostSubmmitOrderHeader(httpPost,mwc,referer);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpPostSubmmitOrderProxy(httpPost,mwc,config);  
    }
    public MaotaiWebCookie sendHttpPostShoppingHandler(String httpUrl, MaotaiWebCookie mwc, Map<String, String> maps) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        httpPost = setHttpPostShoppingHandlerHeader(httpPost, mwc);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }
        return sendHttpPostShoppingHandler(httpPost,mwc);  
    }
    
    
    /** 
     * @param httpUrl ��ַ 
     */  
    public String sendHttpPost(String httpUrl, String params) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        try {  
            StringEntity stringEntity = new StringEntity(params, "UTF-8");  
            stringEntity.setContentType("application/x-www-form-urlencoded");  
            httpPost.setEntity(stringEntity);  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return sendHttpPost(httpPost);  
    }    
    /** 
     */  
    public String sendHttpPost(String httpUrl, Map<String, String> maps) {  
        HttpPost httpPost = new HttpPost(httpUrl);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
        for (String key : maps.keySet()) {  
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));  
        }  
        try {  
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return sendHttpPost(httpPost);  
    }  
    
    private MaotaiWebCookie sendHttpPostSubmmitOrderProxy(HttpPost httpPost,MaotaiWebCookie mwc,RequestConfig config) {  
        CloseableHttpClient httpClient = null;  
        CloseableHttpResponse response = null;  
        HttpEntity entity = null;  
        String responseContent = null;  
        try {  
            httpClient = HttpClients.createDefault(); 
            httpPost.setConfig(config);  
            response = httpClient.execute(httpPost); 
            Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						System.out.println(hea.getName()+"-------"+hea.getValue());
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}else if(hea.getValue().startsWith("Location")){
							mwc.setLocal(hea.getValue());
						}
					}
				}
			}
            entity = response.getEntity();  
            if(entity!=null){
            	responseContent = EntityUtils.toString(entity, "UTF-8");  
            	mwc.setContent(responseContent);
            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (response != null) {  
                    response.close();  
                }  
                if (httpClient != null) {  
                    httpClient.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return mwc;  
    }
    private MaotaiWebCookie sendHttpPostSubmmitOrder(HttpPost httpPost,MaotaiWebCookie mwc) {  
        CloseableHttpClient httpClient = null;  
        CloseableHttpResponse response = null;  
        HttpEntity entity = null;  
        String responseContent = null;  
        try {  
            httpClient = HttpClients.createDefault(); 
            httpPost.setConfig(requestConfig);  
            response = httpClient.execute(httpPost); 
            Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						System.out.println(hea.getName()+"-------"+hea.getValue());
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}else if(hea.getValue().startsWith("Location")){
							mwc.setLocal(hea.getValue());
						}
					}
				}
			}
            entity = response.getEntity();  
            if(entity!=null){
            	responseContent = EntityUtils.toString(entity, "UTF-8");  
            	System.out.println(responseContent);
            	mwc.setContent(responseContent);
            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (response != null) {  
                    response.close();  
                }  
                if (httpClient != null) {  
                    httpClient.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return mwc;  
    }
    private MaotaiWebCookie sendHttpGetUserShippingAddressPostProxy(HttpPost httpPost,MaotaiWebCookie mwc,RequestConfig config) {  
        CloseableHttpClient httpClient = null;  
        CloseableHttpResponse response = null;  
        HttpEntity entity = null;  
        String responseContent = null;  
        try {  
            httpClient = HttpClients.createDefault(); 
            httpPost.setConfig(config);  
            response = httpClient.execute(httpPost); 
            Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}
					}
				}
			}
            entity = response.getEntity();  
            if(entity!=null){
            	responseContent = EntityUtils.toString(entity, "UTF-8");  
            	mwc.setContent(responseContent);
            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (response != null) {  
                    response.close();  
                }  
                if (httpClient != null) {  
                    httpClient.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return mwc;  
    }  
    private MaotaiWebCookie sendHttpGetUserShippingAddressPost(HttpPost httpPost,MaotaiWebCookie mwc) {  
        CloseableHttpClient httpClient = null;  
        CloseableHttpResponse response = null;  
        HttpEntity entity = null;  
        String responseContent = null;  
        try {  
            httpClient = HttpClients.createDefault(); 
            httpPost.setConfig(requestConfig);  
            response = httpClient.execute(httpPost); 
            Header[] headers = response.getAllHeaders();
			if (headers != null && headers.length > 0) {
				for (Header hea : headers) {
					if("Set-Cookie".equals(hea.getName())){
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}
					}
				}
			}
            entity = response.getEntity();  
            if(entity!=null){
            	responseContent = EntityUtils.toString(entity, "UTF-8");  
            	mwc.setContent(responseContent);
            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (response != null) {  
                    response.close();  
                }  
                if (httpClient != null) {  
                    httpClient.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return mwc;  
    }  
    
    private MaotaiWebCookie sendHttpLoginPostProxy(HttpPost httpPost,RequestConfig config) {  
        CloseableHttpClient httpClient = null;  
        CloseableHttpResponse response = null;  
        MaotaiWebCookie mwc = new MaotaiWebCookie();
        try {  
            httpClient = HttpClients.createDefault(); 
            httpPost.setConfig(config);  
            response = httpClient.execute(httpPost); 
            Header[] headers = response.getAllHeaders();
            if(headers!=null&&headers.length>0){
            	for (Header hea : headers) {
					if(hea.getName().contains("Set-Cookie")){
						System.out.println(hea.getName() + "::::::::::::::"
    							+ hea.getValue());
						if(hea.getValue().startsWith(".Hidistro")){
							mwc.setHidistro(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}
					}
				}
            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (response != null) {  
                    response.close();  
                }  
                if (httpClient != null) {  
                    httpClient.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return mwc;  
    } 
    private MaotaiWebCookie sendHttpLoginPost(HttpPost httpPost) {  
        CloseableHttpClient httpClient = null;  
        CloseableHttpResponse response = null;  
        MaotaiWebCookie mwc = new MaotaiWebCookie();
//        HttpEntity entity = null;  
//        String responseContent = null;  
//        String serverId = "";
        try {  
            httpClient = HttpClients.createDefault(); 
            httpPost.setConfig(requestConfig);  
            response = httpClient.execute(httpPost); 
            
//            entity = response.getEntity();  
//            if(entity!=null){
//            	responseContent = EntityUtils.toString(entity, "UTF-8");  
//            }
            Header[] headers = response.getAllHeaders();
            if(headers!=null&&headers.length>0){
            	for (Header hea : headers) {
					if(hea.getName().contains("Set-Cookie")){
						System.out.println(hea.getName() + "::::::::::::::"
    							+ hea.getValue());
						if(hea.getValue().startsWith(".Hidistro")){
							mwc.setHidistro(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}
					}
				}
            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (response != null) {  
                    response.close();  
                }  
                if (httpClient != null) {  
                    httpClient.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return mwc;  
    }  
    private String sendHttpPost(HttpPost httpPost) {  
        CloseableHttpClient httpClient = null;  
        CloseableHttpResponse response = null;  
        HttpEntity entity = null;  
        String responseContent = null;  
        try {  
            httpClient = HttpClients.createDefault(); 
            httpPost.setConfig(requestConfig);  
            response = httpClient.execute(httpPost); 
            
            entity = response.getEntity(); 
            System.out.println(response.getStatusLine().getStatusCode());
            if(entity!=null){
            	responseContent = EntityUtils.toString(entity, "UTF-8");  
            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (response != null) {  
                    response.close();  
                }  
                if (httpClient != null) {  
                    httpClient.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return responseContent;  
    }  
    private MaotaiWebCookie sendHttpPostShoppingHandler(HttpPost httpPost,MaotaiWebCookie mwc) {  
        CloseableHttpClient httpClient = null;  
        CloseableHttpResponse response = null;  
//        HttpEntity entity = null;  
//        String responseContent = null;  
        int return_int = 0;
        try {  
            httpClient = HttpClients.createDefault(); 
            httpPost.setConfig(requestConfig);  
            response = httpClient.execute(httpPost); 
            
//            entity = response.getEntity(); 
            return_int = response.getStatusLine().getStatusCode();
            mwc.setCode(return_int);
            Header[] headers = response.getAllHeaders();
            if(headers!=null&&headers.length>0){
            	for (Header hea : headers) {
					if(hea.getName().contains("Set-Cookie")){
						System.out.println(hea.getName() + "::::::::::::::"
    							+ hea.getValue());
						if(hea.getValue().startsWith(".HishopRoles")){
							mwc.setHishopRoles(hea.getValue());
						}else if(hea.getValue().startsWith("SERVERID")){
							mwc.setServerId(hea.getValue());
						}
					}
				}
            }
            System.out.println(response.getStatusLine().getStatusCode());
//            if(entity!=null){
//            	responseContent = EntityUtils.toString(entity, "UTF-8");  
//            }
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            try {  
                if (response != null) {  
                    response.close();  
                }  
                if (httpClient != null) {  
                    httpClient.close();  
                }  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return mwc;  
    }  
    
    
	public static byte[] readInputStream(InputStream inStream) throws Exception {
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = 0;
		while ((len = inStream.read(buffer)) != -1) {
			outStream.write(buffer, 0, len);
		}
		inStream.close();
		return outStream.toByteArray();
	}

	public static void writeImageToDisk(byte[] img, String fileName) {
		try {
			File file = new File("C:\\" + fileName);
			FileOutputStream fops = new FileOutputStream(file);
			fops.write(img);
			fops.flush();
			fops.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}